/**
 * Spring 2012 TCSS360 Deliverable 3
 * Otis Alexander
 */

package storage;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;

public class ReadXMLFile {

	private File xml;
	private DocumentBuilderFactory dBF;
	private Document doc;

	public ReadXMLFile() {
		xml = new File("file.xml");
		dBF = DocumentBuilderFactory.newInstance();
	}

	public void readFile() {
		DocumentBuilder dB;
		try {
			dB = dBF.newDocumentBuilder();
			doc = dB.parse(xml);
			doc.getDocumentElement().normalize();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public NodeList getNodeList(String nodeName) {
		NodeList nList = doc.getElementsByTagName(nodeName);
		return nList;
	}

	public String getAttributeValue(String attributeName,
			Element element) {
		return element.getAttribute(attributeName);
	}
}